package com.gongzhiyun.springboot3test.controller;

import com.gongzhiyun.springboot3test.base.PageBean;
import com.gongzhiyun.springboot3test.base.R;
import com.gongzhiyun.springboot3test.entity.novel.*;
import com.gongzhiyun.springboot3test.service.NovelService;
import com.gongzhiyun.springboot3test.validate.CommonValidate;
import com.gongzhiyun.springboot3test.vo.NovelCommentData;
import com.gongzhiyun.springboot3test.vo.NovelCommentReplyData;
import com.gongzhiyun.springboot3test.vo.NovelShelfData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@Slf4j
@RequestMapping("/novel")
@Tag(name = "小说的相关功能")
public class NovelController {

    private final NovelService novelService;

    @GetMapping("/getLastId")
    public Integer getLastId() {
        return novelService.getLastId();
    }

    @Operation(summary = "根据id查询小说简介", description = "根据id查询小说简介")
    @GetMapping("/queryNovelById/{novelId}")
    public R<NovelList> queryNovelById(@PathVariable("novelId") Integer novelId) {
        return novelService.queryNovelById(novelId);
    }

    @Operation(summary = "查询关于小说的评论", description = "查询小说评论")
    @GetMapping("/queryComment/{pn}/{ps}/{order}")
    public R<List<NovelCommentData>> queryComment(NovelComment novelComment, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps, @PathVariable("order") Integer order) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        pageBean.setOrder(order);
        return novelService.queryComment(novelComment, pageBean);
    }

    @Operation(summary = "查询关于小说评论的回复", description = "查询小说评论回复")
    @GetMapping("/queryReply/{pn}/{ps}/{order}")
    public R<List<NovelCommentReplyData>> queryReply(NovelCommentReply novelCommentReply, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps, @PathVariable("order") Integer order) {
        PageBean pageBean = new PageBean();
        pageBean.setPageNum(pn);
        pageBean.setPageSize(ps);
        pageBean.setOrder(order);
        return novelService.queryReply(novelCommentReply, pageBean);
    }


    @Operation(summary = "对某个小说的评论操作", description = "评论小说")
    @PostMapping("/comment")
    public R<String> comment(@RequestBody NovelComment novelComment) {
        return novelService.comment(novelComment);
    }

    @Operation(summary = "对某个小说的回复操作", description = "回复小说评论")
    @PostMapping("/commentReply")
    public R<String> commentReply(@RequestBody NovelCommentReply novelCommentReply) {
        return novelService.commentReply(novelCommentReply);
    }

    @Operation(summary = "点赞小说评论", description = "点赞小说评论")
    @GetMapping("/praiseComment/{id}")
    public R<String> praiseComment(@PathVariable("id") Integer id) {
        return novelService.praiseComment(id);
    }

    @Operation(summary = "点赞小说评论回复", description = "点赞小说评论回复")
    @GetMapping("/praiseCommentReply/{id}")
    public R<String> praiseCommentReply(@PathVariable("id") Integer id) {
        return novelService.praiseCommentReply(id);
    }

    @Operation(summary = "用户评分小说", description = "用户对某个小说的评分")
    @PostMapping("/userRatings")
    public R<String> userRatings(@RequestBody @Validated(CommonValidate.add.class) NovelUserRatings userRatings) {
        return novelService.userRatings(userRatings);
    }

    @Operation(summary = "查询小说女频", description = "查询小说类型")
    @GetMapping("/queryTypesF")
    public R<List<NovelTypes>> queryTypesF() {
        return novelService.queryTypesF();
    }

    @Operation(summary = "查询小说男频", description = "查询小说类型")
    @GetMapping("/queryTypesM")
    public R<List<NovelTypes>> queryTypesM() {
        return novelService.queryTypesM();
    }

    @Operation(summary = "查询登录用户书架内容", description = "查询用户书架,需要登录")
    @GetMapping("/queryShelf")
    public R<List<NovelShelfData>> queryShelf() {
        return novelService.queryShelf();
    }

    @Operation(summary = "加入书架", description = "加入书架,需要登录")
    @GetMapping("/joinShelf/{id}")
    public R<String> joinShelf(@PathVariable("id") Integer novelId) {
        return novelService.joinShelf(novelId);
    }

    @Operation(summary = "加入小说", description = "加入小说,需要登录")
    @PostMapping("/joinNovel")
    public R<String> joinNovel(@RequestBody NovelList novelList) {
        return novelService.joinNovel(novelList);
    }

    @Operation(summary = "加入小说章节内容", description = "加入小说章节内容")
    @PostMapping("/joinChapter")
    public R<String> joinChapter(@RequestBody NovelChapter novelChapter) {
        return novelService.joinChapter(novelChapter);
    }

    @Operation(summary = "查询小说列表", description = "查询小说")
    @GetMapping("/queryNovel/{pn}/{ps}")
    public R<List<NovelList>> queryNovel(NovelList novelList, @PathVariable("pn") Integer pn, @PathVariable("ps") Integer ps) {
        return novelService.queryNovel(novelList, PageBean.instance(pn, ps));
    }


    @Operation(summary = "查询小说章节内容", description = "查询小说章节")
    @GetMapping("/getChapter/{id}/{novelId}")
    public R<NovelChapter> getChapter(@PathVariable("id") Integer id, @PathVariable("novelId") Integer novelId) {
        return novelService.getChapter(id, novelId);
    }


    @Operation(summary = "查询小说章节列表", description = "查询小说章节列表")
    @GetMapping("/queryChapter/{id}")
    public R<List<NovelChapter>> queryChapter(@PathVariable("id") Integer id) {
        return novelService.queryChapter(id);
    }


    @Operation(summary = "保存用户阅读进度", description = "保存用户阅读进度，需要登录")
    @GetMapping("/saveReading/{novelId}/{chapterId}")
    public R<String> saveReading(@PathVariable("novelId") Integer novelId, @PathVariable("chapterId") Integer chapterId) {
        NovelReading novelReading = new NovelReading();
        novelReading.setNovelId(novelId);
        novelReading.setChapterId(chapterId);

        return novelService.saveReading(novelReading);
    }


    @Operation(summary = "查询用户阅读进度", description = "查询用户阅读进度,需要登录")
    @GetMapping("/getReading/{novelId}")
    public R<NovelReading> getReading(@PathVariable("novelId") Integer novelId) {
        return novelService.getReading(novelId);
    }


    @Operation(summary = "查询用户历史阅读", description = "查询用户历史阅读,需要登录")
    @GetMapping("/getHistoryReading")
    public R<List<NovelShelfData>> getHistoryReading() {
        return novelService.getHistoryReading();
    }


}
